package com.efuture.springbootinit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description: TODO
 * @author: zhaoshanshan
 * @create: 2021-10-28 21:11
 **/
@Controller
public class InitController {

    @Value("${name}")
    private String name;
    @Value("${person.name}")
    private String name2;

    @Value("${person.age}")
    private int age;

    @Value("${address1[1]}")
    private String address;

    @Value("${msg1}")
    private String msg1;

    @Value("${msg2}")
    private String msg2;

    @Autowired
    private Environment env;

    @Autowired
    private Person person;

    @RequestMapping("/init")
    @ResponseBody
    public String init(){
        return "springboot init";
    }
    @RequestMapping("/testValue")
    @ResponseBody
    public void testValue(){
        System.out.println(name);
        System.out.println(name2);
        System.out.println(age);
        System.out.println(address);
        System.out.println(msg1);
        System.out.println(msg2);

        System.out.println("===============");
        System.out.println(env.getProperty("name"));
        System.out.println(env.getProperty("address[0]"));

        System.out.println("------------");
        System.out.println(person.toString());
        String[] address = person.getAddress();
        for (String s : address) {
            System.out.println(s);
        }
    }

}
